import 'dart:typed_data';

import 'package:chathouse/net/ApiPath.dart';
import 'package:chathouse/public/Config.dart';
import 'package:dio/dio.dart';

class Apis {
  static Future<Response?> doPost(String apiName, params,
      {Map<String, dynamic>? queryParameters, isUrlencodedType = false}) {
    return Net.getInstance().requestApi('post', apiName, params,
        queryParameters: queryParameters, isUrlencodedType: isUrlencodedType);
  }

  static Future<Response?> doGet(String apiName,
      {params, isUrlencodedType = false}) {
    return Net.getInstance()
        .requestApi('get', apiName, params, isUrlencodedType: isUrlencodedType);
  }

  static Future<Response?> doPut(String apiName,
      {data, params, isUrlencodedType = false}) {
    return Net.getInstance()
        .requestApi('put', apiName, params, isUrlencodedType: isUrlencodedType);
  }

  static Future<Response?> doDelegate(String apiName,
      {data, params, isUrlencodedType = false}) {
    return Net.getInstance().requestApi('delete', apiName, params,
        isUrlencodedType: isUrlencodedType);
  }

  /// 查询APP最新的版本
  static Future<Response?> getAppVersion() {
    return doGet(ApiPath.getAppVersion);
  }

  /// 是否顯示遊客模式
  static Future<Response?> isShowTourist() {
    return doGet(ApiPath.isShowTourist);
  }

  ///** 登陸註冊相關 ***///
  /// 用戶註冊
  static Future<Response?> userRegister(params,
      {Map<String, dynamic>? queryParameters}) {
    return doPost(ApiPath.user_register, params,
        queryParameters: queryParameters);
  }

  /// 登录
  static Future<Response?> login(params,
      {Map<String, dynamic>? queryParameters}) {
    return doPost(ApiPath.login, params, queryParameters: queryParameters);
  }

  static Future<Response?> touristregister(params,
      {Map<String, dynamic>? queryParameters}) {
    return doGet(ApiPath.touristregister,
        params: params, isUrlencodedType: true);
  }

  static Future<Response?> deleteMember(params,
      {Map<String, dynamic>? queryParameters}) {
    return doDelegate(ApiPath.deleteMember,
        params: params, isUrlencodedType: true);
  }

  /// 登出
  static Future<Response?> loginOut(params,
      {Map<String, dynamic>? queryParameters}) {
    return doGet(ApiPath.loginOut);
  }

  /// 注册查重
  static Future<Response?> duplicateChecking(params) {
    return doPost(ApiPath.duplicateChecking, params);
  }

  /// 发送邮箱验证码
  static Future<Response?> getEmailCode(params) {
    return doPost(ApiPath.geteMailCode, {}, queryParameters: params);
  }

  /// 发送sms证码
  static Future<Response?> getSmsCode(params) {
    return doPost(ApiPath.getSMSCode, {},
        queryParameters: params, isUrlencodedType: true);
  }

  /// 獲取隱私政策
  static Future<Response?> getPrivacy() {
    return doGet(ApiPath.getAgreement);
  }

  /// 忘記密碼
  static Future<Response?> forgetPwdByEmail(params) {
    return doGet(ApiPath.forgetPwdbyEmail, params: params);
  }

  ///** 登陸註冊相關end ***///

  ///** 问题相关 ***///

  // 上传图片
  static Future<Response?> uploadFile(Uint8List imageData, String fileName) {
    var image = MultipartFile.fromBytes(imageData, filename: fileName);
    FormData formData = FormData.fromMap({"file": image});
    return Net.getInstance().postForm(ApiPath.uploadFile, params: formData);
  }

  // 前置页 根据serviceId查询题库
  static Future<Response?> listByServiceId(params) {
    return doGet(ApiPath.listByServiceId, params: params);
  }

  // 下一页
  static Future<Response?> nextPage(params) {
    return doPost(ApiPath.nextPage, params);
  }

  // 下一页,提交
  static Future<Response?> nextPageSubmit(params, queryParameters) {
    return doPost(ApiPath.nextPageSubmit, params,
        queryParameters: queryParameters);
  }

  // 专家列表
  static Future<Response?> getExpList(int serviceId) {
    return doGet(ApiPath.getExpertList, params: {"serviceId": serviceId});
  }

  // 提交选择专家
  static Future<Response?> subSelectExpert(params) {
    return doPost(ApiPath.subSelectExpert, params);
  }

  // 专家弹窗答题
  static Future<Response?> getExpQuestionList(int disinfestationServiceId) {
    return doGet(ApiPath.getExpertQuestionList,
        params: {"disinfestationServiceId": disinfestationServiceId});
  }

  ///** 问题相关end ***///

  ///广告
  static Future<Response?> getAdvertise(params) {
    return doGet(ApiPath.getAdvertise, params: params);
  }

  ///  客户端首页热门服务
  static Future<Response?> getHotServiceList() {
    return doGet(ApiPath.getHotServiceList);
  }

  ///  客户端首页热门服务
  static Future<Response?> getHotServiceListSix() {
    return doGet(ApiPath.getHotServiceListSix);
  }

  /// 客户端-搜索頁面-热门服务
  static Future<Response?> getHotList() {
    return doGet(ApiPath.getHotList);
  }

  /// 客户端獲取服務詳細信息
  static Future<Response?> getServiceDetail(num serViceId) {
    return doGet(ApiPath.getServiceDetail + "$serViceId");
  }

  /// 获取会员详细信息(membersNo)
  static Future<Response?> getMembersInfoForNo(dynamic memberNo) {
    return doGet(ApiPath.getMembersInfoForNo + "$memberNo");
  }

  /// 客户端獲取法令检测接口
  static Future<Response?> getLegalEngineerService() {
    return doGet(ApiPath.getLegalEngineerService);
  }

  /// 客户端獲取服務接口
  static Future<Response?> getServiceList() {
    return doGet(ApiPath.getServiceList);
  }

  /// 客户端獲取維修及工程
  static Future<Response?> getEngineeringList() {
    return doGet(ApiPath.getEngineeringList);
  }

  /// 客户端獲取維修及工程
  static Future<Response?> getOrderList(params) {
    String url =
        "${ApiPath.getOrderList}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url, params: params, isUrlencodedType: true);
  }

  /// 用户端*订单*全部
  static Future<Response?> getAllOrderList(params) {
    String url =
        "${ApiPath.getAllOrderList}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url, isUrlencodedType: true);
  }

  ///  评价专家
  static Future<Response?> commonExpert(params) {
    return doPut(ApiPath.commonExpert, params: params);
  }

  ///  用户聘用专家
  static Future<Response?> hireExpert(params) {
    return doPut(ApiPath.hireExpert, params: params, isUrlencodedType: true);
  }

  ///  修改会员信息
  static Future<Response?> editMember(params) {
    return doPut(ApiPath.editMember, params: params, isUrlencodedType: false);
  }
  ///  修改会员信息
  static Future<Response?> confirmPayment(params) {
    return doPut(ApiPath.confirmPayment, params: params, isUrlencodedType: false);
  }


  ///  获取会员详细信息(无参，默认当前登录用户)
  static Future<Response?> getMembersInfo() {
    return doGet(ApiPath.getMembersInfo);
  }

  /// 重設密碼
  static Future<Response?> resetPassword(params) {
    return doGet(ApiPath.resetPassword, params: params);
  }

  /// 重設密碼
  static Future<Response?> contact(params) {
    return doPost(ApiPath.contact, params);
  }

  /// 获取当前登录用户的電郵及通知設定详细信息
  static Future<Response?> getMemberSettingInfo() {
    return doGet(ApiPath.getMemberSettingInfo);
  }

  /// 修改電郵及通知設定
  static Future<Response?> updateMemberSettingInfo(params) {
    return doPut(ApiPath.updateMemberSettingInfo, params: params);
  }

  ///  修改会话列表
  static Future<Response?> updateChatRecord(params) {
    return doPut(ApiPath.updateChatRecord, params: params);
  }

  /// 批量已读聊天记录
  static Future<Response?> updateChatMsgRead(params) {
    return doPut(ApiPath.updateChatMsgRead, params: params);
  }

  ///  用projectId获取会话列表详细信息
  static Future<Response?> queryChatDetailOfProjectId(params) {
    return doGet(ApiPath.queryChatDetailOfProjectId,
        params: params, isUrlencodedType: true);
  }

  ///獲取我的評語
  static Future<Response?> getMembersComUser(params) {
    String url =
        "${ApiPath.getMembersComUser}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url, isUrlencodedType: true);
    // return doGet(ApiPath.membersComUser,isUrlencodedType: true);
  }

  ///*******************************專家接口*******************************///
  static Future<Response?> expertInfo() {
    return doGet(ApiPath.expertInfo);
  }

  static Future<Response?> getCommentDetail() {
    return doGet(ApiPath.getCommentDetail);
  }

  /// 金幣列表數據
  static Future<Response?> speciesList() {
    return doGet(ApiPath.speciesList);
  }

  /// 獲取支付鏈接
  static Future<Response?> paymentLinksById(params) {
    return doGet(ApiPath.paymentLinksById,
        params: params, isUrlencodedType: true);
  }

  ///專家服務
  static Future<Response?> Shieldlist(params) {
    String url =
        "${ApiPath.shieldlist}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url);
  }

  ///對話列表
  static Future<Response?> getSessionList(params) {
    String url =
        "${ApiPath.expertMessage}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url, params: params, isUrlencodedType: true);
  }

  /// 服务详情
  static Future<Response?> serviceDetail(String params) {
    String url = ApiPath.serviceDetail + params;
    return doGet(url);
  }

  // 预览
  static Future<Response?> simpleServiceDetail(String params) {
    String url = ApiPath.simpleServiceDetail + params;
    return doGet(url);
  }

  /// 报价
  static Future<Response?> serviceQuote(params) {
    String url = ApiPath.quote;
    return doPost(url, params);
  }

  /// approvalRecharge
  static Future<Response?> addApprovalRecharge(params) {
    String url = ApiPath.approvalRecharge;
    return doPost(url, params);
  }

  /// approvalRecharge
  static Future<Response?> approvalRecharge(params) {
    String url = ApiPath.approvalRecharge;
    return doPut(url, params: params);
  }

  static Future<Response?> templateServicelist(params) {
    String url = ApiPath.templateServicelist;
    return doGet(url, isUrlencodedType: true);
  }

  ///充值记录
  static Future<Response?> cerList(params) {
    String url = "${ApiPath.cerList}?pageNum=1&pageSize=50";
    return doGet(url, params: params);
  }

  static Future<Response?> cerDetail(params) {
    String url = ApiPath.cerDetail + params;
    return doGet(url);
  }

  // 充值反馈
  static Future<Response?> cerApprovalRecharge(params) {
    String url = ApiPath.cerApprovalRecharge;
    return doPut(url, params: params, isUrlencodedType: false);
  }

  ///查看項目權限
  static Future<Response?> getLookProjectPermission(params) {
    return doGet(ApiPath.getLookProjectPermission,
        params: params, isUrlencodedType: true);
  }

  /// 通知列表 用户传“0”，专家传“1”
  static Future<Response?> getPushList(params) {
    String url =
        "${ApiPath.pushList}?pageNum=${params["pageNum"]}&pageSize=20&reasonable=false";
    return doGet(url, params: params, isUrlencodedType: true);
  }

  static Future<Response?> templateList(params) {
    return doGet(ApiPath.templateList, isUrlencodedType: true);
  }

  // 新增模本
  static Future<Response?> addTemplate(params) {
    return doPost(ApiPath.template, params);
  }

  static Future<Response?> editTemplate(params) {
    return doPut(ApiPath.template, params: params);
  }

  // 圖表
  static Future<Response?> queryChartData(params) {
    return doGet(ApiPath.queryChartData,
        params: params, isUrlencodedType: true);
  }

  // 订单号
  static Future<Response?> getTradingCode(params) {
    return doGet(ApiPath.getTradingCode, isUrlencodedType: true);
  }

  static Future<Response?> expertComUser(params) {
    return doGet(ApiPath.expertComUser, isUrlencodedType: true);
  }

  /// 用户之间聊天记录
  static Future<Response?> getMessageChatRecord(params) {
    String url = ApiPath.messageInfo +
        params["reviceuserid"] +
        "?pageNum=${params["pageNum"]}&pageSize=20";
    return doGet(url, params: params, isUrlencodedType: true);
  }

  // 专家我的项目
  static Future<Response?> expertOrderList(params) {
    String url =
        "${ApiPath.orderList}?pageNum=${params["pageNum"]}&pageSize=20";
    return doGet(url, params: params);
  }

  // 消息已读
  static Future<Response?> messageReadSet(params) {
    String url = ApiPath.messageReadSet;
    return doPut(url, params: params, isUrlencodedType: true);
  }

  //查询当前用户，多种，未读数量
  static Future<Response?> readNum(params) {
    String url = ApiPath.readNum;
    return doGet(url, params: params, isUrlencodedType: true);
  }
}
